package xu.ye.view.adapter;

import java.util.List;

import com.agent.crm.bean.MyContact;
import com.agent.crm.view.R;

import xu.ye.bean.ContactBean;
import xu.ye.view.ContactSelectActivity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class ContactSelectAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private List<MyContact> list;
    private Context ctx;
    private int workType;
    
    public ContactSelectAdapter(Context ctx, LayoutInflater inflater, List<MyContact> list, int workType){
        this.ctx = ctx;
        this.list = list;
        this.inflater = inflater;
        this.workType = workType;
    }
    

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.contact_multiple_choice, null);
            holder = new ViewHolder();
            
            holder.multileContact = (TextView) convertView.findViewById(R.id.multileContactId);
            holder.name = (TextView) convertView.findViewById(R.id.contactNameId);
            holder.checkBox = (CheckBox) convertView.findViewById(R.id.contactCheckBoxId);
            convertView.setTag(holder);
            
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        MyContact cb = list.get(position);
        holder.multileContact.setText(cb.getContactsId() + "");
        holder.name.setText(cb.getName());
        Boolean bool;
        if(workType == ContactSelectActivity.WORK_TYPE_TYPE){
            int belongType = cb.getBelongType();
            bool = (belongType == 1)? true : false;
        }
        else{
            int belongGroup = cb.getBelongGroup();
            bool = (belongGroup == 1)? true : false;
        }
         
        holder.checkBox.setChecked(bool);
        return convertView;
    }
    
    
    
    
    
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    
    private static class ViewHolder {
        TextView multileContact;
        TextView name;
        CheckBox checkBox;
        
    }
    
    
}
